home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 10.2 KB | 339 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Utils.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWBMPSHP_H
- #include "FWBmpShp.h"
- #endif
-
- #ifndef FWPICSHP_H
- #include "FWPicShp.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw
- #endif
-
- //========================================================================================
- // class CGrid
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CGrid::CGrid
- //----------------------------------------------------------------------------------------
-
- CGrid::CGrid(unsigned short rows, unsigned short columns,
- const FW_CPoint& position,
- const FW_CPoint& cellInterior,
- FW_CFixed penSize) :
- fRows(rows),
- fColumns(columns),
- fCellSize(cellInterior.x + penSize, cellInterior.y + penSize),
- fHalfPenSize(penSize.Half()),
- fPosition(position.x + penSize.Half(), position.y + penSize.Half())
- {
-
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::FindCell
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CGrid::FindCell(const FW_CPoint& where, unsigned long& index) const
- {
- FW_CRect rect;
- unsigned long lastIndex = fRows * fColumns;
- for (unsigned long x = 0; x < lastIndex; x++)
- {
- GetCellInterior(x, rect);
- if (rect.Contains(where))
- {
- index = x;
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::FindCell
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CGrid::FindCell(const FW_CPoint& where, unsigned short& row, unsigned short& column) const
- {
- FW_CRect rect;
- for (unsigned short x = 0; x < fColumns; x++)
- for (unsigned short y = 0; y < fRows; y++)
- {
- GetCellInterior(y, x, rect);
- if (rect.Contains(where))
- {
- column = x;
- row = y;
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetCellInterior
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetCellInterior(unsigned short row, unsigned short column, FW_CRect& rect) const
- {
- FW_ASSERT(row <= fRows && column <= fColumns);
- rect.Set(FW_IntToFixed(0), FW_IntToFixed(0), fCellSize.x, fCellSize.y);
- rect.Place(fCellSize.x.MultipliedByInt(column), fCellSize.y.MultipliedByInt(row));
- rect.Inset(fHalfPenSize, fHalfPenSize);
- rect.Offset(fPosition.x, fPosition.y);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetCellInterior
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetCellInterior(unsigned long index, FW_CRect& rect) const
- {
- unsigned short row, column;
- GetRowColumn(index, row, column);
- GetCellInterior(row, column, rect);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetCellExterior
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetCellExterior(unsigned short row, unsigned short column, FW_CRect& rect) const
- {
- FW_ASSERT(row <= fRows && column <= fColumns);
- rect.Set(FW_IntToFixed(0), FW_IntToFixed(0), fCellSize.x, fCellSize.y);
- rect.Place(fCellSize.x.MultipliedByInt(column), fCellSize.y.MultipliedByInt(row));
- rect.Inset(-fHalfPenSize, -fHalfPenSize);
- rect.Offset(fPosition.x, fPosition.y);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetCellExterior
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetCellExterior(unsigned long index, FW_CRect& rect) const
- {
- unsigned short row, column;
- GetRowColumn(index, row, column);
- GetCellExterior(row, column, rect);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetRowColumn
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetRowColumn(unsigned long index, unsigned short& row, unsigned short& column) const
- {
- row = index / fColumns;
- column = index - (row * fColumns);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetExteriorGridRect
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetExteriorGridRect(FW_CRect& rect) const
- {
- rect.Set(FW_IntToFixed(0), FW_IntToFixed(0), fCellSize.x.MultipliedByInt(fColumns), fCellSize.y.MultipliedByInt(fRows));
- rect.Inset(-fHalfPenSize, -fHalfPenSize);
- rect.Offset(fPosition.x, fPosition.y);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::GetInteriorGridRect
- //----------------------------------------------------------------------------------------
-
- void CGrid::GetInteriorGridRect(FW_CRect& rect) const
- {
- rect.Set(FW_IntToFixed(0), FW_IntToFixed(0), fCellSize.x.MultipliedByInt(fColumns), fCellSize.y.MultipliedByInt(fRows));
- rect.Inset(fHalfPenSize, fHalfPenSize);
- rect.Offset(fPosition.x, fPosition.y);
- }
-
- //----------------------------------------------------------------------------------------
- // CGrid::DrawGridBorders
- //----------------------------------------------------------------------------------------
-
- void CGrid::DrawGridBorders(FW_CFacetContext& fc, const FW_PInk& ink, const FW_PStyle& style)
- {
- FW_CPoint position(fPosition.x - fHalfPenSize, fPosition.y - fHalfPenSize);
- FW_CLineShape line(position.x, position.y, position.x + fCellSize.x.MultipliedByInt(fColumns), position.y);
- line.SetInk(ink);
- line.SetStyle(style);
- unsigned short i;
- for (i = 0; i <= fRows; i++)
- {
- line.Render(fc);
- line.MoveShape(FW_IntToFixed(0), fCellSize.y);
- }
-
- line.SetLineStart(position.x, position.y);
- line.SetLineEnd(position.x, position.y + fCellSize.y.MultipliedByInt(fRows));
- for (i = 0; i <= fColumns; i++)
- {
- line.Render(fc);
- line.MoveShape(fCellSize.x, FW_IntToFixed(0));
- }
- }
-
- //========================================================================================
- // class CWidget
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CWidget::CWidget
- //----------------------------------------------------------------------------------------
-
- CWidget::CWidget(FW_ResourceId resId) :
- fResId(resId)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CWidget::~CWidget
- //----------------------------------------------------------------------------------------
-
- CWidget::~CWidget()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CWidget::Render
- //----------------------------------------------------------------------------------------
-
- void CWidget::Render(FW_CFacetContext& fc, const FW_CRect& rect)
- {
- FW_CSharedLibraryResourceFile partResFile;
-
- #ifdef FW_BUILD_MAC
- FW_PPicture picture(partResFile, fResId);
- FW_CPictureShape::RenderPicture(fc, picture, rect);
- #endif
- #ifdef FW_BUILD_WIN
- FW_PBitmap bitmap(partResFile, fResId);
- FW_CBitmapShape::RenderBitmap(fc, bitmap, rect);
- #endif
- }
-
- //========================================================================================
- // class CDrawReadableStream
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawReadableStream::CDrawReadableStream
- //----------------------------------------------------------------------------------------
-
- CDrawReadableStream::CDrawReadableStream(Environment* ev,
- CDrawPart* drawPart,
- FW_CStorageUnitSink* sink,
- FW_CCloneInfo* cloneInfo):
- FW_CReadableStream(sink),
- fEnvironment(ev),
- fDrawPart(drawPart),
- fCloneInfo(cloneInfo)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawReadableStream::CDrawReadableStream
- //----------------------------------------------------------------------------------------
-
- CDrawReadableStream::~CDrawReadableStream()
- {
- FW_START_DESTRUCTOR
- }
-
- //========================================================================================
- // class CDrawWritableStream
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawWritableStream::CDrawWritableStream
- //----------------------------------------------------------------------------------------
-
- CDrawWritableStream::CDrawWritableStream(Environment* ev, FW_CStorageUnitSink* sink, FW_CCloneInfo* cloneInfo):
- FW_CWritableStream(sink),
- fEnvironment(ev),
- fCloneInfo(cloneInfo)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawWritableStream::CDrawWritableStream
- //----------------------------------------------------------------------------------------
-
- CDrawWritableStream::~CDrawWritableStream()
- {
- FW_START_DESTRUCTOR
- }
-
-
-
-